package com.google.code.vannevar.server.framework;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.google.inject.Guice;

public final class GuiceListener implements ServletContextListener {

    @Override
    public void contextDestroyed(ServletContextEvent event) {
        
        // Nothing to do
    }

    @Override
    public void contextInitialized(ServletContextEvent event) {
        
        ServletContext context = event.getServletContext(); 

        try {

            context.setAttribute("injector",
                    Guice.createInjector(new ApplicationModule()));

        } catch (Exception exception) {
            
            context.log("Unable to load Guice Module.", exception);
        }
    }
}
